package dao.xml.xstream;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.Connection;
import java.util.Collection;

import model.Datentraeger;
import model.Film;
import model.ModelBase;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;

import dao.DAO;

public class DatentraegerXStreamDAO implements DAO<Datentraeger> 
{

  @Override
  public Datentraeger read(InputStream in) throws IOException 
  {
    return (Datentraeger) createXStream().fromXML(in);
  }

  @Override
  public Collection<Datentraeger> readMultiple(InputStream in) throws IOException 
  {
    return null;
  }

  @Override
  public void write(OutputStream out, Datentraeger data) throws IOException 
  {
    createXStream().toXML(data, out);
    out.flush();
  }

  @Override
  public void writeMultiple(OutputStream out, Collection<Datentraeger> data) throws IOException 
  {
    // TODO Auto-generated method stub
  }

  private XStream createXStream() {
    XStream xStream = new XStream(new DomDriver());
    xStream.alias("datentraeger", Datentraeger.class);
    xStream.useAttributeFor(Datentraeger.class, "name");
    xStream.aliasField("datentraegerName", Datentraeger.class, "name");
    xStream.alias("film", Film.class);
    xStream.useAttributeFor(Film.class, "name");
    xStream.aliasField("filmName", Film.class, "name");
    xStream.useAttributeFor(Film.class, "hauptdarsteller");
    xStream.useAttributeFor(Film.class, "genre");
    xStream.useAttributeFor(Film.class, "laenge");
    return xStream;
  }

  @Override
  public int save(Connection connection, ModelBase data) 
  {
	// TODO Auto-generated method stub
	return 0;
  }

  @Override
  public int delete(Connection connection, ModelBase data) 
  {
	// TODO Auto-generated method stub
	return 0;
  }

}